﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Traceability.Commont.DBContexts;
using Traceability.Commont.Domains;
using Traceability.Commont.Infrastructures.Interfaces;

namespace Traceability.Commont.Infrastructures.Repository
{
    public class BateRepository<T> : IBateRepository<T> where T : class,new ()
    {
        private readonly EFDBContext db;

        public BateRepository(EFDBContext db)
        {
            this.db = db;
        }

        public async Task<int> Add(T entity)
        {
            db.Set<T>().Add(entity);
            return await db.SaveChangesAsync();
        }

        public async Task<int> AddRang(List<T> entities)
        {
            db.Set<T>().AddRange(entities);
            return await db.SaveChangesAsync();
        }
        public IQueryable<T> GetAll()
        {
            return db.Set<T>().AsQueryable();
        }

        public async Task<int>  Update(T entity)
        {
            db.Set<T>().Update(entity);
            return await db.SaveChangesAsync();
        }
        public async Task<int> Delete(T entity)
        {
            db.Set<T>().Remove(entity);
            return await db.SaveChangesAsync();
        }
    }
}
